using System;
using Headspring.Training.Domain.Model;
using Headspring.Training.Domain.Services;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using Rhino.Mocks;


namespace Headspring.Training.Domain.UnitTests.Services
{
    [TestFixture]
    public class SmsSenderTester
    {
        [Test]
        public void ShouldSendSmsMessage()
        {
            WorkOrderNotification notification = new WorkOrderNotification();
            Employee employee1 = new Employee("", "", "", "");
            employee1.MobileNumber = "1234567";
            notification.To = employee1;
            WorkOrder workorder1 = new WorkOrder();
            workorder1.Number = "X123";
            workorder1.Status = WorkOrderStatus.Cancelled;
            notification.WorkOrder = workorder1;
            notification.PreviousStatus = WorkOrderStatus.InProgress;


            MockRepository mocks = new MockRepository();
            IWirelessSender wirelesssender = mocks.CreateMock<IWirelessSender>();
            wirelesssender.Send(null);
            SmsMessage actualmessage = null;
            LastCall.IgnoreArguments().Do(new Action<SmsMessage>(delegate(SmsMessage obj) { actualmessage = obj; }));
            mocks.ReplayAll();

            ISmsSender sender = new SmsSender(wirelesssender);
            sender.Send(notification);
            mocks.VerifyAll();
            
            Assert.That(actualmessage.WirelessNumber, Is.EqualTo(notification.To.MobileNumber));
            Assert.That(actualmessage.MessageContents, Is.EqualTo("X123 changed from In Progress to Cancelled"));
        }

        [Test]
        public void ShouldSendSpecialSmsMessage()
        {
            WorkOrderNotification notification = new WorkOrderNotification();
            Employee employee1 = new Employee("", "", "", "");
            employee1.MobileNumber = "1234567";
            notification.To = employee1;
            WorkOrder workorder1 = new WorkOrder();
            workorder1.Number = "X123";
            workorder1.Status = WorkOrderStatus.Assigned;
            notification.WorkOrder = workorder1;
            notification.PreviousStatus = WorkOrderStatus.Complete;


            MockRepository mocks = new MockRepository();
            IWirelessSender wirelesssender = mocks.CreateMock<IWirelessSender>();
            wirelesssender.Send(null);
            SmsMessage actualmessage = null;
            LastCall.IgnoreArguments().Do(new Action<SmsMessage>(delegate(SmsMessage obj) { actualmessage = obj; }));
            mocks.ReplayAll();

            ISmsSender sender = new SmsSender(wirelesssender);
            sender.Send(notification);
            mocks.VerifyAll();

            Assert.That(actualmessage.MessageContents, Is.EqualTo("X123 changed from Complete to Assigned. Check your work better next time!"));
            
        }
    }
}